package com.nkym.wypan.enums;

import java.util.HashMap;
import java.util.Map;

public enum PreviewHeader {
    TXT(1, "text/plain"),
    DOC(2, "application/msword"),
    DOCX(3, "application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
    XLS(4, "application/vnd.ms-excel"),
    XLSX(5, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
    PPT(6, "application/vnd.ms-powerpoint"),
    PPTX(7, "application/vnd.openxmlformats-officedocument.presentationml.presentation"),
    PDF(8, "application/pdf"),
    HTML(9, "text/html"),
    XML(10, "application/xml"),
    JSON(11, "application/json"),
    YAML(12, "application/x-yaml"),
    JPG(13, "image/jpeg"),
    JPEG(14, "image/jpeg"),
    PNG(15, "image/png"),
    BMP(16, "image/bmp"),
    GIF(17, "image/gif"),
    WEBP(18, "image/webp"),
    SVG(19, "image/svg+xml"),
    MP3(20, "audio/mpeg"),
    WAV(21, "audio/x-wav"),
    FLAC(22, "audio/flac"),
    AAC(23, "audio/aac"),
    APE(24, "audio/ape"),
    MP4(25, "video/mp4"),
    AVI(26, "video/x-msvideo"),
    MOV(27, "video/quicktime"),
    RMVB(28, "video/vnd.rn-realvideo"),
    MKV(29, "video/x-matroska"),
    WMV(30, "video/x-ms-wmv"),
    ZIP(31, "application/zip"),
    RAR(32, "application/x-rar-compressed"),
    _7Z(33, "application/x-7z-compressed"),
    TAR_GZ(34, "application/x-gzip-compressed-tar"),
    BZ2(35, "application/x-bzip2"),
    EXE(36, "application/x-msdownload"),
    MSI(37, "application/x-msi"),
    DMG(38, "application/x-apple-diskimage"),
    DEB(39, "application/x-debian-package"),
    RPM(40, "application/x-rpm"),
    APK(41, "application/vnd.android.package-archive"),
    IPA(42, "application/octet-stream"),
    DB(43, "application/x-sqlite3"),
    SQLITE(44, "application/x-sqlite3"),
    MDB(45, "application/vnd.ms-access"),
    ACCDB(46, "application/msaccess"),
    SQL(47, "text/x-sql"),
    TTF(48, "font/ttf"),
    OTF(49, "font/otf"),
    WOFF(50, "font/woff"),
    WOFF2(51, "font/woff2"),
    JAVA(52, "text/x-java-source"),
    C(53, "text/x-csrc"),
    CPP(54, "text/x-c++src"),
    PY(55, "text/x-python"),
    RUBY(56, "text/x-ruby"),
    PHP(57, "application/x-httpd-php"),
    JS(58, "application/javascript"),
    CSS(59, "text/css"),
    LESS(60, "text/less"),
    SCSS(61, "text/x-scss"),
    SASS(62, "text/x-sass"),
    LOG(63, "text/plain"),
    CSV(64, "text/csv"),
    EPUB(65, "application/epub+zip"),
    MOBI(66, "application/x-mobipocket-ebook"),
    AI(67, "application/postscript"),
    EPS(68, "application/postscript"),
    PSD(69, "image/vnd.adobe.photoshop"),
    OTHER(99, "application/octet-stream");

    private static final Map<Integer, PreviewHeader> VALUE_MAP = new HashMap<>();
    private static final Map<String, PreviewHeader> CONTENT_TYPE_MAP = new HashMap<>();

    static {
        for (PreviewHeader header : values()) {
            VALUE_MAP.put(header.value, header);
            CONTENT_TYPE_MAP.put(header.contentType, header);
        }
    }

    public final int value;
    public final String contentType;

    PreviewHeader(int value, String contentType) {
        this.value = value;
        this.contentType = contentType;
    }

    public static PreviewHeader fromValue(int value) {
        return VALUE_MAP.getOrDefault(value, OTHER);
    }

    public static PreviewHeader fromContentType(String contentType) {
        return CONTENT_TYPE_MAP.getOrDefault(contentType, OTHER);
    }
}
